package com.dykj.fireFighting.server.base.analysis.service.impl;

import com.alibaba.nacos.common.utils.UuidUtils;
import com.dykj.fireFighting.api.base.analysis.dto.ComprehensiveQueryDto;
import com.dykj.fireFighting.api.base.analysis.entity.FaultRecoveryRecord;
import com.dykj.fireFighting.api.base.analysis.service.IFaultRecoveryRecordService;
import com.dykj.fireFighting.api.base.analysis.vo.ComprehensiveResultFLVo;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.utils.DateTimeCutUtil;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.server.base.analysis.mapper.FaultRecoveryRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * 设备恢复记录
 *
 * @Author JacksonTu
 * @Date  2022-04-22 16:53:29
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class FaultRecoveryRecordServiceImpl extends BaseServiceImpl<FaultRecoveryRecordMapper, FaultRecoveryRecord> implements IFaultRecoveryRecordService {
        @Autowired
        private IEnterpriseService iEnterpriseService;
    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryQSByUnits(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryQSByUnits(queryDto);
    }

    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryQSByArea(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryQSByArea(queryDto);
    }

    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryQSByIndustry(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryQSByIndustry(queryDto);
    }

    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryPHByUnits(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryPHByUnits(queryDto);
    }

    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryPHByArea(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryPHByArea(queryDto);
    }

    @Override
    public List<ComprehensiveResultFLVo> getFaultRecoveryPHByIndustry(ComprehensiveQueryDto queryDto) {
        return this.baseMapper.getFaultRecoveryPHByIndustry(queryDto);
    }

    @Override
    public void bsave() throws ParseException {
        Random random = new Random();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<Enterprise> enterprises=iEnterpriseService.selectByType(0);
        List<String> day = DateTimeCutUtil.cutByType("2019-01-01", "2021-12-11", "month");
        for (Enterprise e:enterprises
             ) {
            for (int i = 0; i <day.size() ; i++) {
                FaultRecoveryRecord faultRecoveryRecord = new FaultRecoveryRecord();
                faultRecoveryRecord.setUnitId(e.getId().toString());
                faultRecoveryRecord.setId(UUIDUtils.get32UUID());
                faultRecoveryRecord.setIsEffective(random.nextInt(2));
                String s = day.get(i) + "-" + (random.nextInt(28) +1) + " 00:00:00";
                Date parse = sdf.parse(s);

                faultRecoveryRecord.setHfTime(parse);
                this.baseMapper.insert(faultRecoveryRecord);
            }

        }



    }
}
